package com.ceair.flight.refund.config;

import com.ceair.flight.refund.service.appmobile.IAppRefundCalculatorService;
import com.ceair.flight.refund.service.appmobile.IAppRefundService;
import com.ceair.flight.refund.service.ota.IRefundService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;

import javax.xml.ws.Endpoint;

/**
 * Java 配置文件
 * @author: Eric Wu e_mail:wuwenjun3@ceair.com
 * @create: 2018/05/22
 */
@Configuration
@PropertySource({"classpath:muconfig/config-common.properties"})
@ImportResource(locations = {"classpath:spring/application-third-party.xml",
        "classpath:spring/applicationContext-refund-cxf-client.xml"})
public class ConfigRefund {

    @Autowired
    private IRefundService refundService;

    @Autowired
    private IAppRefundCalculatorService appRefundCalculatorService;

    @Autowired
    private IAppRefundService appRefundService;

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        return new ServletRegistrationBean(new CXFServlet(), "/service/*");
    }

//    @Bean(name = Bus.DEFAULT_BUS_ID)
//    public SpringBus springBus() {
//        return new SpringBus();
//    }

//    @Bean
//    public Endpoint refundEndpoint() {
//        EndpointImpl endpoint = new EndpointImpl(springBus(),refundService);
//        endpoint.publish("/refundService");
//        return endpoint;
//    }
//
//    @Bean
//    public Endpoint appRefundCalculator() {
//        EndpointImpl endpoint = new EndpointImpl(springBus(),appRefundCalculatorService);
//        endpoint.publish("/appRefundCalculatorService");
//        return endpoint;
//    }
//
//    @Bean
//    public Endpoint appRefund() {
//        EndpointImpl endpoint = new EndpointImpl(springBus(), appRefundService);
//        endpoint.publish("/appRefundService");
//        return endpoint;
//    }


    @Bean("jsonProvider") // 构造一个json转化bean，用于将student转化为json，因为后面需要用这个bean配置json转化，所以给他取个名
    public JacksonJsonProvider jsonProvider(){
        JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
        return jsonProvider;
    }
}
